/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author shinji
 */
@Entity
@Table(name = "Friend")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Friend.findAll", query = "SELECT f FROM Friend f"),
    @NamedQuery(name = "Friend.findById", query = "SELECT f FROM Friend f WHERE f.id = :id"),
    @NamedQuery(name = "Friend.findByRequest", query = "SELECT f FROM Friend f WHERE f.request = :request"),
    @NamedQuery(name = "Friend.findByRequestContext", query = "SELECT f FROM Friend f WHERE f.requestContext = :requestContext")})
public class Friend implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private Integer id;
    @Column(name = "Request")
    private Boolean request;
    @Size(max = 50)
    @Column(name = "RequestContext")
    private String requestContext;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "iDFriend")
    private List<Message> messageList;
    @JoinColumn(name = "ID_Member", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private Member1 iDMember;
    @JoinColumn(name = "ID_Friend", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private Member1 iDFriend;

    public Friend() {
    }

    public Friend(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Boolean getRequest() {
        return request;
    }

    public void setRequest(Boolean request) {
        this.request = request;
    }

    public String getRequestContext() {
        return requestContext;
    }

    public void setRequestContext(String requestContext) {
        this.requestContext = requestContext;
    }

    @XmlTransient
    public List<Message> getMessageList() {
        return messageList;
    }

    public void setMessageList(List<Message> messageList) {
        this.messageList = messageList;
    }

    public Member1 getIDMember() {
        return iDMember;
    }

    public void setIDMember(Member1 iDMember) {
        this.iDMember = iDMember;
    }

    public Member1 getIDFriend() {
        return iDFriend;
    }

    public void setIDFriend(Member1 iDFriend) {
        this.iDFriend = iDFriend;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Friend)) {
            return false;
        }
        Friend other = (Friend) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.Friend[ id=" + id + " ]";
    }
    
}
